<?
	
class extTree{
 
	/*
	 * Load tree node.
	 */	
	 function getTree($dbObject,$node,$appid,$target){
		$nodes = $this->display_children($dbObject,$node,$appid,$target);

		print json_encode($nodes);
	}
 

	function display_children($dbObject,$parent,$appid,$target) {
		// retrieve all children of $parent
		$result = $dbObject->query(  'SELECT * ' .
								'FROM news_column ' . 
								'WHERE parent_id = ' . $parent . ' ' .
								'ORDER BY orderBy;');

		// display each child
		while ($row = mysql_fetch_array($result)) {
			// Response parameters.
			
			$path['text']		= iconv('gb2312','utf-8',$row['name']);
			$path['id']			= $row['id'];
			$path['position']	= $row['orderBy'];
			$path['href']	    = "admin.php?appid=".$appid."&column_id=".$row['id'];
			$path['hrefTarget']	= $target;

			// Check if node is a leaf or a folder.
			$cResult = $dbObject->query( 'SELECT * ' .
									'FROM news_column ' .
									'WHERE parent_id = ' . $row['id'] . ' ' .
									'ORDER BY orderBy;');
			$cCount = mysql_num_rows($cResult);
			if($cCount > 0){
				$path['leaf']	= false;
				$path['cls']	= 'folder';
			}else{
				$path['leaf']	= true;
				$path['cls']	= 'file';
			}
 
			// call this function again to display this
			// child's children
			$nodes[] = $path;
		}
		return $nodes;
	}
 
 
}

?>